<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>用户修改密码</title>
		<link rel="stylesheet" href="./layui/css/layui.css">
		<script type="text/javascript" src="js/global.js"></script>
		<script src="./layui/layui.js"></script>
	</head>

	<body>
		<form class="layui-form" onsubmit="false">
			<div class="layui-form-item" style="margin-top: 20px">
				<label class="layui-form-label">旧密码：</label>
				<div class="layui-input-inline" style="width: 350px">
					<input type="password" name="pwd" id="pwd" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">新密码：</label>
				<div class="layui-input-inline" style="width: 350px">
					<input type="password" name="password" id="password" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-btn-container" style="text-align: center;">
					<button class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
				</div>
			</div>
		</form>

		<script>
			//Demo
			layui.use(['form'], function() {
				var form = layui.form;
				var $ = layui.jquery;
				//解决跨域
				$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
					options.xhrFields = {
						withCredentials: true
					}
				})
				//监听提交
				form.on('submit(formDemo)', function(data) {
					var d = {
						'pwd': $("#pwd").val(),
						'password': $("#password").val(),
					}; //表单中的数据，定义一个对象来接收
					var url = globalData.server + './public/updatePwd?name=' + globalData.getUserName() + "&id=" + globalData.getUid();
					$.post(url, d, function(res) {
						console.log(res);
						if(res.succ) {
							globalData.loginOut();
							window.location.href = "login.html";
						} else {
							console.log(res.message);
							layer.msg(res.message, {
								icon: 2,
								time: 4000
							});
						}
					}, "json");
					return false;
				});
			});
		</script>
	</body>

</html>